@@ -2,7 +2,7 @@ class JobsController < ApplicationController |
||
2 | 2 |
before_filter :authenticate_admin! |
3 | 3 |
|
4 | 4 |
def index |
5 |
- @jobs = Delayed::Job.page(params[:page]) |
|
5 |
+ @jobs = Delayed::Job.order("coalesce(failed_at,'1000-01-01'), run_at asc").page(params[:page]) |
|
6 | 6 |
|
7 | 7 |
respond_to do |format| |
8 | 8 |
format.html { render layout: !request.xhr? } |
@@ -50,6 +50,6 @@ class JobsController < ApplicationController |
||
50 | 50 |
|
51 | 51 |
private |
52 | 52 |
def running? |
53 |
- @job.locked_at || @job.locked_by |
|
53 |
+ (@job.locked_at || @job.locked_by) && @job.failed_at.nil? |
|
54 | 54 |
end |
55 | 55 |
end |
@@ -47,9 +47,9 @@ |
||
47 | 47 |
</div> |
48 | 48 |
</td> |
49 | 49 |
<td> |
50 |
- <% if !job.locked_at && !job.locked_by %> |
|
50 |
+ <% if (!job.locked_at && !job.locked_by) || job.failed_at.present? %> |
|
51 | 51 |
<div class="btn-group btn-group-xs" style="float: right"> |
52 |
- <% if job.run_at > Time.now %> |
|
52 |
+ <% if (job.run_at > Time.now) || job.failed_at.present? %> |
|
53 | 53 |
<%= link_to 'Run now', run_job_path(job), class: "btn btn-default", method: :put %> |
54 | 54 |
<% end %> |
55 | 55 |
<%= link_to 'Delete', job_path(job), class: "btn btn-danger", method: :delete, data: { confirm: 'Really delete this job?' } %> |
@@ -72,7 +72,7 @@ class HuginnScheduler |
||
72 | 72 |
|
73 | 73 |
def cleanup_failed_jobs! |
74 | 74 |
num_to_keep = (ENV['FAILED_JOBS_TO_KEEP'].presence || FAILED_JOBS_TO_KEEP).to_i |
75 |
- first_to_delete = Delayed::Job.where.not(failed_at: nil).order("failed_at DESC").offset(num_to_keep).limit(num_to_keep).pluck(:failed_at).first |
|
75 |
+ first_to_delete = Delayed::Job.where.not(failed_at: nil).order("failed_at DESC").offset(num_to_keep).limit(1).pluck(:failed_at).first |
|
76 | 76 |
Delayed::Job.where(["failed_at <= ?", first_to_delete]).delete_all if first_to_delete.present? |
77 | 77 |
end |
78 | 78 |
|
@@ -4,12 +4,12 @@ describe JobsController do |
||
4 | 4 |
|
5 | 5 |
describe "GET index" do |
6 | 6 |
before do |
7 |
- Delayed::Job.create |
|
8 |
- Delayed::Job.create |
|
7 |
+ Delayed::Job.create! |
|
8 |
+ Delayed::Job.create! |
|
9 | 9 |
Delayed::Job.count.should > 0 |
10 | 10 |
end |
11 | 11 |
|
12 |
- it "does not allow normal users"do |
|
12 |
+ it "does not allow normal users" do |
|
13 | 13 |
sign_in users(:bob) |
14 | 14 |
get(:index).should redirect_to(root_path) |
15 | 15 |
end |
@@ -40,6 +40,7 @@ describe JobsController do |
||
40 | 40 |
before do |
41 | 41 |
@not_running = Delayed::Job.create(run_at: Time.now - 1.hour) |
42 | 42 |
@running = Delayed::Job.create(locked_at: Time.now, locked_by: 'test') |
43 |
+ @failed = Delayed::Job.create(run_at: Time.now - 1.hour, locked_at: Time.now, failed_at: Time.now) |
|
43 | 44 |
sign_in users(:jane) |
44 | 45 |
end |
45 | 46 |
|
@@ -47,6 +48,10 @@ describe JobsController do |
||
47 | 48 |
expect { put :run, id: @not_running.id }.to change { @not_running.reload.run_at } |
48 | 49 |
end |
49 | 50 |
|
51 |
+ it "queue a job that failed" do |
|
52 |
+ expect { put :run, id: @failed.id }.to change { @failed.reload.run_at } |
|
53 |
+ end |
|
54 |
+ |
|
50 | 55 |
it "not queue a running job" do |
51 | 56 |
expect { put :run, id: @running.id }.not_to change { @not_running.reload.run_at } |
52 | 57 |
end |